package com.coderside.fragment.arithmetic;

public class AA {

	static int[] arr = { 2, 3, 5, 7, 11, 13, 17, 19 };

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int r = lcm(15, 12);
		System.out.println(r);
		getAllfactor(70);
		System.out.println();
	}

	/**
	 * 求所有的因数
	 * @param num
	 * @return
	 */
	private static long getAllfactor(long num) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < arr.length;) {
			int factor = arr[i];
			if (num % factor == 0) {
				sb.append(factor + ",");
				num = num / factor;
			} else {
				i++;
			}
		}
		System.out.println(sb);
		return 0;
	}


	/**
	 * 求最小公倍数
	 * @param a
	 * @param b
	 * @return
	 */
	private static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	/**
	 * 求最大公约数
	 * @param a
	 * @param b
	 * @return
	 */
	private static int gcd(int a, int b) {
		int temp;
		if (a < b)/*交换两个数，使大数放在a上*/
		{
			temp = a;
			a = b;
			b = temp;
		}
		while (b != 0)/*利用辗除法，直到b为0为止*/
		{
			temp = a % b;
			a = b;
			b = temp;
		}
		return a;
	}

}
